const app = getApp()
const $api = require('../../../utils/api.js').API;

Page({
    data: {
        count:0,
        list:{},
        page:1,
        pageShow:true,
    },
    onLoad: function() {
       this.getMoneyCount();
       this.getMoneyList();
    },
    getMoneyCount:function(){
        var that = this
        var data = {'uid':wx.getStorageSync('uid')}
        $api.get('member/info',data).then(res => {

            //请求成功
            if(res.data.code == 1){
              that.setData({
                count:res.data.data.money
              })
            }
        }).catch(err => {
            //请求失败
            console.log('job','请求失败');
        })
    },
    getMoneyList:function(){
        var that = this
        var data = {'uid':wx.getStorageSync('uid'),'page':this.data.page}
        var list = this.data.list
        $api.get('money/money',data).then(res => {
            //请求成功
            if(res.data.code == 1){
                if(res.data.data.last_page <= that.data.page){
                    that.setData({
                        pageShow:false
                    })
                }
                if(that.data.page == 1){
                    that.setData({
                        list:res.data.data.data
                    })
                }else{
                    that.setData({
                        list:list.concat(res.data.data.data)
                    })
                }
            }
        }).catch(err => {
            //请求失败
            console.log('job','请求失败');
        })
    },
    onReachBottom: function(t){
        if(this.data.pageShow){
            //当前不是最后一页可加载
            this.setData({
                page: this.data.page + 1,
            })
            //wx.showNavigationBarLoading()
            this.getMoneyList();
        }
    },
    onShareAppMessage: function() {
        return {
            title: "天意美业直通车",
            path: "/pages/index/index?puid="+wx.getStorageSync('uid')
        };
      }
});